#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e3 + 7;
int dp[MAXN][MAXN];

int main(){
	string s,t;
	cin >> s >> t;
	int len1 = s.size();
	int len2 = t.size();
	for(int i = 1;i <= len1;i++){
		for(int j = 1;j <= len2;j++){
			if(s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]);
		}
	}
	string str = "";
	int i = len1,j = len2;
	while(i != 0 && j != 0){
		if(s[i - 1] == t[j - 1]){
			str += s[i - 1];
			i--;
			j--;
		}else{
			dp[i - 1][j] < dp[i][j - 1] ? j--:i--;
		}
	}
	for(int i = str.size() - 1;i >= 0;i--)
		cout << str[i];
	cout << "\n";
}